///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.service.sys.system.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.plian.Tools.CollectionUtil;
//import com.plian.system.config.exception.MyRuntimeException;
//import com.plian.system.entity.sys.FormColumnName;
//import com.plian.system.entity.sys.FormHistoryRecord;
//import com.plian.system.mapper.sys.FormHistoryRecordMapper;
//import com.plian.system.model.ObjResult;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.service.fr.enterprise.IEnterpriseService;
//import com.plian.system.service.fr.vehicle.IVehicleInfoService;
//import com.plian.system.service.hr.dept.IDeptService;
//import com.plian.system.service.hr.staff.IStaffFilesService;
//import com.plian.system.service.im.IProjectInfoService;
//import com.plian.system.service.sys.system.IFormColumnNameService;
//import com.plian.system.service.sys.system.IQueryHistoryRecordService;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.sys.QueryHistoryRecordVO;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.FormTypeConstant.*;
//
///**
// * 表单历史记录 服务实现类
// *
// * @author jianglei
// * @since 2019-10-23
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class QueryHistoryRecordServiceImpl extends BaseServiceImpl<FormHistoryRecordMapper, FormHistoryRecord> implements IQueryHistoryRecordService {
//
//	private IStaffFilesService staffFilesService;
//
//	private IDeptService deptService;
//
//	private IFormColumnNameService formColumnNameService;
//
//	private IEnterpriseService enterpriseService;
//
//	private IProjectInfoService projectInfoService;
//
//	private IVehicleInfoService vehicleInfoService;
//
//	@Override
//	public QueryHistoryRecordVO getDetail(FormHistoryRecord formHistoryRecord) {
//		Object recordId = formHistoryRecord.getRecordId();
//		List<FormHistoryRecord> list = list(new LambdaQueryWrapper<FormHistoryRecord>()
//				.eq(FormHistoryRecord::getRecordId, formHistoryRecord.getRecordId()).orderByAsc(FormHistoryRecord::getVersion));
//		Integer oldVersion = formHistoryRecord.getVersion();
//		if (oldVersion == null){
//			throw new MyRuntimeException(new ObjResult("历史数据--> version为null！"));
//		}
//
//		QueryHistoryRecordVO queryHistoryRecordVO = new QueryHistoryRecordVO();
//		if (CollectionUtil.isNotEmpty(list)){
//			queryHistoryRecordVO.setOldRecord(JSON.parseObject(list.get(oldVersion - 1).getRecord()));
//
//			Integer formType = Integer.valueOf(formHistoryRecord.getFormType());
//
//			List<FormColumnName> formColumnNames = formColumnNameService.list(new LambdaQueryWrapper<FormColumnName>()
//					.eq(FormColumnName::getFormType, formType).eq(FormColumnName::getIsShow, 2).orderByAsc(FormColumnName::getOrderNumber));
//			if (CollectionUtil.isEmpty(formColumnNames)){
//				throw new MyRuntimeException(new ObjResult("历史数据--> 表单数据未配置！"));
//			}
//
//			List<HeaderVO> headerVOS = formColumnNames.stream().map(formColumnName -> {
//				return HeaderVO.builder().key(formColumnName.getColumnName())
//						.title(formColumnName.getFieldName()).build();}).collect(Collectors.toList());
//
//			queryHistoryRecordVO.setHeader(headerVOS);
//			if (oldVersion.equals(list.get(list.size()-1).getVersion())){
//				switch (formType){
//					case HR_STAFFFILES_FORM:
//						queryHistoryRecordVO.setNewRecord(staffFilesService.getDetailVO(recordId));
//						break;
//					case HR_DEPT:
//						queryHistoryRecordVO.setNewRecord(deptService.getDetailVO(recordId));
//						break;
//					case FR_ENTERPRISE:
//						queryHistoryRecordVO.setNewRecord(enterpriseService.getEnterpriseVO(recordId));
//						break;
//					case PROJECT_INFO:
//						queryHistoryRecordVO.setNewRecord(projectInfoService.getDetailVO(recordId));
//						break;
//					case FR_VEHICLE_INFO:
//						queryHistoryRecordVO.setNewRecord(vehicleInfoService.getDetailVO(recordId));
//						break;
//					default:
//						throw new MyRuntimeException(new ObjResult("历史数据--> 未知的单据类型！"));
//				}
//			}else {
//				queryHistoryRecordVO.setNewRecord(JSON.parseObject(list.get(oldVersion).getRecord()));
//			}
//
//		}
//		return queryHistoryRecordVO;
//	}
//}
